package com.wjsima.renyisima.demo;

import java.util.*;
import java.util.function.Consumer;
import java.util.function.Function;
import java.util.stream.Collectors;
import java.util.stream.Stream;

/*
四. Function接口使用

1.使用lambda表达式分别将以下功能封装到Function对象中
 a)求Integer类型ArrayList中所有元素的平均数
 b)将Map<String,Integer>中value存到ArrayList<Integer>中
 姓名	成绩
岑小村	59
谷天洛	82
渣渣辉	98
蓝小月	65
皮几万	70
 */
public class HomeWork4 {
    public static void main(String[] args) {
        Student s1 = new Student("岑小村",59);
        Student s2 = new Student("谷天洛",82);
        Student s3 = new Student("渣渣辉",98);
        Student s4 = new Student("蓝小月",65);
        Student s5 = new Student("皮几万",70);
        Student [] stu = {s1,s2,s3,s4,s5};
        Stream<Student> stream = Arrays.stream(stu);
//        Stream<Map> rStream = stream.map(new Function<String, Integer>() {
//            @Override
//            public String apply(String s) {
//                return null;
//            }
//        });
        Stream<Integer> integerStream = stream.map(new Function<Student, Integer>() {
            @Override
            public Integer apply(Student student) {
                return student.getScore();
            }
        });
        List<Integer> collect = integerStream.collect(Collectors.toList());
        int sum =0;
        for (Integer integer : collect) {
            sum += integer;
        }
        int avg = sum / collect.size();
        System.out.println(avg);
        HashMap<String,Integer> map = new HashMap<>();


    }
}
